#include "list.h"
#include <iostream>
#include <string>
using namespace std;
 
double Sum = 0.0;
List::List()
{
	top = 0;
}
bool List::isempty() const
{
	return top == 0;
}
bool List::isfull() const
{
	return top == Len;
}
bool List::add(const Item& item)
{
    if (top < Len)
    {
        items[top++] = item;
        return true;
    }
    else
        return false;
}
void List::showitem() const
{
    for (int i = 0; i < top; i++)
    {
        cout << "#" << i + 1 <<":"<< endl;
        cout << "Name: " << items[i].name << endl;
        cout << "Consumption: " << items[i].consumption << endl;
    }
}
void List::visit(void(*pf)(Item& item))
{
    for (int i = 0; i < top; i++)
    {
        pf(items[i]);
    }
}

void List::turnover(Item& item)
{
    Sum += item.consumption;
}
